home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / plnk081.zip / pilot-link.0.8.1 / install-user.c < prev    next >
C/C++ Source or Header  |  1997-08-03  |  3KB  |  108 lines

  1. /* install-user.c:  User name
  2.  *
  3.  * This is free software, licensed under the GNU Public License V2.
  4.  * See the file COPYING for details.
  5.  */
  6.  
  7. /* Note: if you use this program to change the user name on the Pilot, I
  8.  * _highly_ reccomend that you perform a hard reset before HotSyncing with a
  9.  * Windows machine. This is because the user-id information has only been
  10.  * partially altered, and it is not worth trying to predict what the Desktop
  11.  * will do. - KJA
  12.  */
  13.  
  14.  
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include "pi-source.h"
  18. #include "pi-socket.h"
  19. #include "pi-dlp.h"
  20.  
  21. int main(int argc, char *argv[])
  22. {
  23.   struct pi_sockaddr addr;
  24.   int sd;
  25.   struct PilotUser U;
  26.   struct SysInfo S;
  27.   struct CardInfo C;
  28.   struct NetSyncInfo N;
  29.   unsigned long romversion;
  30.   int ret;
  31.  
  32.   if (argc < 2) {
  33.     fprintf(stderr,"usage:%s %s [User name [User ID]]\n",argv[0],TTYPrompt);
  34.     exit(2);
  35.   }
  36.  
  37.   if (!(sd = pi_socket(PI_AF_SLP, PI_SOCK_STREAM, PI_PF_PADP))) {
  38.     perror("pi_socket");
  39.     exit(1);
  40.   }
  41.     
  42.   addr.pi_family = PI_AF_SLP;
  43.   strcpy(addr.pi_device,argv[1]);
  44.   
  45.   ret = pi_bind(sd, (struct sockaddr*)&addr, sizeof(addr));
  46.   if(ret == -1) {
  47.     perror("pi_bind");
  48.     exit(1);
  49.   }
  50.  
  51.   ret = pi_listen(sd, 1);
  52.   if(ret == -1) {
  53.     perror("pi_listen");
  54.     exit(1);
  55.   }
  56.  
  57.   sd = pi_accept(sd, 0, 0);
  58.   if(sd < 0) {
  59.     perror("pi_accept");
  60.     exit(1);
  61.   }
  62.   
  63.   /* Tell user (via Pilot) that we are starting things up */
  64.   dlp_OpenConduit(sd);
  65.  
  66.   dlp_ReadUserInfo(sd, &U);
  67.   
  68.   dlp_ReadSysInfo(sd, &S);
  69.   
  70.   C.card = -1;
  71.   C.more = 1;
  72.   while(C.more) {
  73.     if(dlp_ReadStorageInfo(sd, C.card+1, &C)<0)
  74.       break;
  75.     
  76.     printf(" Card #%d has %lu bytes of ROM, and %lu bytes of RAM (%lu of that is free)\n",
  77.        C.card, C.romSize, C.ramSize, C.ramFree);
  78.     printf(" It is called '%s', and was made by '%s'.\n", C.name, C.manufacturer);
  79.   }
  80.   
  81.  
  82.   if (argc == 2) {
  83.     printf ("Pilot user %s\n",U.username);
  84.     printf("UserID %ld \n", U.userID );
  85.   }
  86.   else {
  87.     strcpy(U.username, argv[2]);
  88.     if (argc == 4) { U.userID = atoi(argv[3]); }
  89.     U.lastSyncDate = time( (time_t *)0);
  90.     dlp_WriteUserInfo(sd, &U);
  91.   }
  92.   
  93.   printf( "Through ReadSysInfo: ROM Version: 0x%8.8lX, locale: 0x%8.8lX, name: '%s'\n", 
  94.               S.romVersion, S.locale, S.name);
  95.  
  96.   dlp_ReadFeature(sd, makelong("psys"), 1, &romversion);
  97.   
  98.   printf( "ROM Version through ReadFeature: 0x%8.8lX\n", romversion);
  99.   
  100.   if (dlp_ReadNetSyncInfo(sd, &N) >= 0) {
  101.     printf( "NetSync: LAN sync = %d, Host name = '%s', address = '%s', netmask ='%s'\n",
  102.         N.lanSync, N.hostName, N.hostAddress, N.hostSubnetMask);
  103.   }
  104.   
  105.   pi_close(sd);
  106.   exit(0);
  107. }
  108.